package org.stu.dao.hibernate;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.stu.dao.UserDao;
import org.stu.dto.User;
import org.stu.dto.UserType;

import junit.framework.TestCase;

public class Test extends  TestCase{
	SessionFactory sessionFactory;
	Session session;
	public void testUser(){
		Configuration config=new Configuration().configure();
		sessionFactory=config.buildSessionFactory();
		session=sessionFactory.openSession();
		
		UserType userType=new UserType();
		User user=new User();
		Set users= new HashSet();
		
		userType.setType("Manager");
		user.setName("dohu123");
		user.setEmail("dohu123@126.com");
		user.setPassword("110");
		user.setAddress("GZ");
		user.setDesc("the owner");
		
		users.add(user);
		userType.setUsers(users);
		user.setUserType(userType);
		
		session.save(user);
		session.save(userType);
		
		session.flush();
		try{
			session.connection().commit(); 
			session.close();
		}catch (Exception e){
			e.printStackTrace();
		}
	
   	 
		
	}

}
